package kr.hkit.powerjava.chapter14.programming;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.FlowLayout;
import javax.swing.BoxLayout;
import javax.swing.SwingConstants;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class MFrame extends JFrame implements ActionListener {

	private JPanel contentPane;
	private MPanel panel;
	private JButton btnNewButton;
	private JTextField tfOut;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MFrame frame = new MFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MFrame() {
		initialize();
	}
	private void initialize() {
		setTitle("마일을 킬로미터로 변환");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 305, 139);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
		
		panel = new MPanel();
		contentPane.add(panel);
		
		btnNewButton = new JButton("변환");
		btnNewButton.addActionListener(this);
		contentPane.add(btnNewButton);
		
		tfOut = new JTextField();
		contentPane.add(tfOut);
		tfOut.setColumns(20);
	}

	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand().equals("변환")){
			int up = Integer.parseInt(panel.getTfIn().trim());
			double mid = 1.6;
			tfOut.setText(up * mid + "");
		}
	}
}
